package star.cloud.asme.base.mybatis.mapperExtend;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class ActiveById extends AbstractMethod {

    public ActiveById(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sql = "update " + tableInfo.getTableName() + " set deleted = 0 " + " where " + tableInfo.getKeyColumn() + " = #{" + tableInfo.getKeyProperty() + "}";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addUpdateMappedStatement(mapperClass, Boolean.class, sqlSource);
    }
}